home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / Codeworks 0.94b3 / Codeworks® WWW Demo Doc. / Scripting Manual.doc / Scripting Manual.doc.rsrc / TEXT_153.txt < prev    next >
Encoding:
Text File  |  1995-05-01  |  4.3 KB  |  99 lines

  1. Miscellaneous Objects
  2.  
  3.     This chapter discusses four unrelated objects: user, transcript, folder and time.  [ the last two are still not discussed ]
  4.  
  5.  
  6. User
  7.     The user object has several messages for interacting with the user via modal notes.  Each of these messages displays a note to the user.  The system will not proceed until the user answers the note by tapping on one of its buttons.
  8.  
  9. ask user msg yes-button y no-button n with-cancel
  10.     This message displays a note with two buttons at the bottom.  The text displayed in the note is the string msg.  By default the two buttons are labeled ‚ÄòYes‚Äô and ‚ÄòNo‚Äô, but the labels can be changed with the yes-button and no-button arguments.  The note is modal and the user cannot continue until a button is tapped.  When the user taps a button, the note is removed and the result of the ask message is true if the user tapped the ‚ÄòYes‚Äô button, and false if they tapped the ‚ÄòNo‚Äô button.
  11.  
  12.     If the optional argument with-cancel is present, then a third button is added labeled ‚ÄòCancel‚Äô.  You can‚Äôt change the text of this button.  If the user taps this button instead of the other two, then the note is removed and the result of the ask message is ???.
  13.  
  14.     Examples:
  15.     a := choose 1 to 10.
  16.  until [ ask user "Do you like the number" && a.name & "?" ]
  17.         do [ a := choose 1 to 10 ].
  18.  
  19.     $ answer.
  20.  a := 23.
  21.     answer := ask user "Change this number?"
  22.         yes-button "Double It"
  23.         no-button "Halve It"
  24.         with-cancel.
  25.  if (answer is-not ???) then [
  26.       if answer then [ a := a * 2 ]
  27.       else [ a := a / 2 ].
  28.     ].
  29.  
  30.  
  31.  
  32. tell user msg ok-button o with-cancel
  33.     This message is very similar to the ask message, except that it only puts up one button with a default label of ‚ÄòOK‚Äô.  You can change the label of the button with the ok-button argument.
  34.  
  35.     This message is often used to tell the user something has been done, or to confirm an action.
  36.  
  37.     Examples:
  38.  tell user "Time for dinner!"
  39.  
  40.     $ confirm.
  41.     confirm := tell user "Really remove bob from the list?"
  42.         ok-button "Remove"
  43.         with-cancel.
  44.  if (confirm is ???) then [ return ].    user canceled
  45.     santas-list remove "bob".
  46.  
  47.  
  48. query user msg default-text d ok-button o with-cancel
  49.     This message displays a note with a write in field.  The write in field starts off with the text supplied by the default-text argument (or blank by default).  In addition, the note has an ‚ÄòOK‚Äô button and an optional ‚ÄòCancel‚Äô button.  The text of the ‚ÄòOK‚Äô button can be changed with the ok-button argument.  The user can edit the text in the write in field. If the user taps the ‚ÄòOK‚Äô button, then the text in the write in field is returned.  If the user taps the ‚ÄòCancel‚Äô button (if any) then ??? is returned.
  50.  
  51.     Examples:
  52.     $ n.
  53.     n := query user "What is your name?".
  54.  tell user "Hello" && n.
  55.  
  56.     $ new-item.
  57.     a := "apples".
  58.     new-item := query user "Enter a fruit:"
  59.         default-text a with-cancel.
  60.  if (new-item is ???) then [ return ].
  61.     a := new-item.
  62.  
  63.  
  64. user choose from g
  65.     This message displays a pop-up menu of the items in the group g.  If the user taps on one of the items, the menu is removed and that item is returned as the result of the choose message.  If the user taps outside the menu, then the menu is removed and ??? is returned.
  66.  
  67.     Example:
  68.     $ animals, new-pet.
  69.     animals := new group.
  70.     animals add "bird".
  71.     animals add "cat".
  72.     animals add "dog".
  73.     animals add "zebra".
  74.     new-pet := user choose from animals.
  75.  if (new-pet is ???) then [ return ].
  76.  return "Eric the" && new-pet.
  77.  
  78.  
  79.  
  80. Transcript
  81.     The transcript is a window that displays text messages.  It is used only for debugging: the window will not exist if you give your completed application to someone without Glyphic Codeworks.  You can have your scripts write text onto the end of the transcript at any time.  This can sometimes help you understand and debug your programs.  The transcript is not infinitely long: it only holds the last several thousand characters.  You can open the transcript from the System menu.
  82.  
  83. transcript put msg
  84.     This is the only message transcript understands.  It appends the string msg to the end of the transcript on a new line.
  85.  
  86.     Example:
  87.     $ n, root-n, old-guess.
  88.     n := 2.
  89.     old-guess := 0.
  90.     root-n := n.extended.
  91.  until [ (root-n - old-guess abs) < 1e-15 ] do [
  92.       old-guess := root-n.
  93.       root-n := (n / old-guess + old-guess) / 2.
  94.       transcript put "root-n is now" &&
  95.         (format root-n using "9.###############").
  96.     ]
  97.  return root-n
  98.  
  99.